/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Principal;

import clases.Conexion;
import java.awt.HeadlessException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;

/**
 *
 * @author Juan
 */
public class frmUsuarios extends javax.swing.JInternalFrame {

    /**
     * Creates new form frmUsuarios
     */
    public frmUsuarios() {
        initComponents();
    }
    Conexion c = new Conexion();
    Connection cn = c.conectar();
    ResultSet r;
    CallableStatement st;
    PreparedStatement ps;
    Statement stm;

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtNumControl = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtAPaterno = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtAMaterno = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        cmbCarrera = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        cmbSemestre = new javax.swing.JComboBox();
        btnGuargar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        btnBuscarAlumno = new javax.swing.JButton();
        tbnActualizarAlumno = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtRFC = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtNombreM = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtAPeternoM = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtAMaternoM = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        cmbCarreraM = new javax.swing.JComboBox();
        btnActualizarMaestro = new javax.swing.JButton();
        btnBuscarMaestro = new javax.swing.JButton();
        btnLimpiar1 = new javax.swing.JButton();
        btnGuargar1 = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Usuarios");

        jPanel1.setBackground(new java.awt.Color(0, 153, 153));

        jLabel1.setText("Num. Control:");

        jLabel2.setText("Nombre:");

        jLabel3.setText("Apellido Paterno:");

        jLabel4.setText("Apellido Materno:");

        jLabel5.setText("Carrera:");

        cmbCarrera.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecciones >>>", "Ing. Industrial", "Ing. Electrica", "Ing. Electronica", "Ing. Mecatronica", "Ing. Mecanica", "Ing. Quimica", "Ing. Sistemas", "Lic. Administracion", "Ing. Bioquimica" }));

        jLabel6.setText("Semestre:");

        cmbSemestre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione>>>", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }));

        btnGuargar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1424340600_04_Save_32x32.png"))); // NOI18N
        btnGuargar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuargarActionPerformed(evt);
            }
        });

        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1424340688_clean.png"))); // NOI18N
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        btnBuscarAlumno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1424340805_Search-Male-User.png"))); // NOI18N
        btnBuscarAlumno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarAlumnoActionPerformed(evt);
            }
        });

        tbnActualizarAlumno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1424340944_system-software-update.png"))); // NOI18N
        tbnActualizarAlumno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbnActualizarAlumnoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNumControl, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNombre))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtAPaterno))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtAMaterno))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbCarrera, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbSemestre, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btnGuargar, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuscarAlumno, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tbnActualizarAlumno, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNumControl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtAPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtAMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cmbCarrera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(cmbSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnGuargar)
                    .addComponent(btnLimpiar)
                    .addComponent(btnBuscarAlumno)
                    .addComponent(tbnActualizarAlumno))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Alumnos", jPanel1);

        jPanel2.setBackground(new java.awt.Color(0, 102, 255));

        jLabel7.setText("RFC:");

        jLabel8.setText("Nombre:");

        jLabel9.setText("Apellido Paterno:");

        jLabel10.setText("Apellido Materno:");

        jLabel11.setText("Carrera:");

        cmbCarreraM.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecciones >>>", "Ing. Industrial", "Ing. Electrica", "Ing. Electronica", "Ing. Mecatronica", "Ing. Mecanica", "Ing. Quimica", "Ing. Sistemas", "Lic. Administracion", "Ing. Bioquimica" }));

        btnActualizarMaestro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1424340944_system-software-update.png"))); // NOI18N
        btnActualizarMaestro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarMaestroActionPerformed(evt);
            }
        });

        btnBuscarMaestro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1424340805_Search-Male-User.png"))); // NOI18N
        btnBuscarMaestro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarMaestroActionPerformed(evt);
            }
        });

        btnLimpiar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1424340688_clean.png"))); // NOI18N
        btnLimpiar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiar1ActionPerformed(evt);
            }
        });

        btnGuargar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/1424340600_04_Save_32x32.png"))); // NOI18N
        btnGuargar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuargar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtRFC, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNombreM))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtAPeternoM))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtAMaternoM))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbCarreraM, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnGuargar1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLimpiar1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(btnBuscarMaestro, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnActualizarMaestro, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtRFC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtNombreM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtAPeternoM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtAMaternoM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbCarreraM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnGuargar1)
                    .addComponent(btnLimpiar1)
                    .addComponent(btnBuscarMaestro)
                    .addComponent(btnActualizarMaestro))
                .addGap(19, 19, 19))
        );

        jTabbedPane1.addTab("Maestros", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGuargar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuargar1ActionPerformed
        //boton guardar Maestro
        //validacion de campos llenos
        if("".equals(txtRFC.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingrese el RFC");
            txtRFC.requestFocusInWindow();
            return;
        }
        if("".equals(txtNombreM.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingresa un Nombre");
            txtNombreM.requestFocusInWindow();
            return;
        }
        if("".equals(txtAPeternoM.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingresa Apellido Paterno");
            txtAPeternoM.requestFocusInWindow();
            return;
        }
        if("".equals(txtAMaternoM.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingresa Apellido Materno");
            txtAMaternoM.requestFocusInWindow();
            return;
        }
        if(cmbCarreraM.getSelectedIndex()==0){
            JOptionPane.showMessageDialog(rootPane, "Selecciona una Carrera");
            return;
        }
        //metodo ingresa maestro
        try {
            ps = cn.prepareCall("{Call RMaestro(?,?,?,?,?)}");
            ps.setString(1, txtRFC.getText());
            ps.setString(2, txtNombreM.getText());
            ps.setString(3, txtAPeternoM.getText());
            ps.setString(4, txtAMaternoM.getText());
            ps.setInt(5, cmbCarreraM.getSelectedIndex());
            int res = ps.executeUpdate();
            if (res == 1) {
                JOptionPane.showMessageDialog(rootPane, "Registro Exitoso");
            }
        } catch (SQLException | HeadlessException e) {
            JOptionPane.showMessageDialog(rootPane, "Error "+e.getMessage());
        }
        txtRFC.setText("");
        txtNombreM.setText("");
        txtAPeternoM.setText("");
        txtAMaternoM.setText("");
        cmbCarreraM.setSelectedIndex(0);
    }//GEN-LAST:event_btnGuargar1ActionPerformed

    private void btnGuargarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuargarActionPerformed
        // boton guardar de Alumnos
        if ("".equals(txtNumControl.getText())) {
            JOptionPane.showMessageDialog(rootPane, "Ingrese Numero de Control");
            txtNumControl.requestFocusInWindow();
            return;
        }
        if ("".equals(txtNombre.getText())) {
            JOptionPane.showMessageDialog(rootPane, "Ingrese el Nombre");
            txtNombre.requestFocusInWindow();
            return;
        }
        if ("".equals(txtAPaterno.getText())) {
            JOptionPane.showMessageDialog(rootPane, "Ingrese el Apellido Paterno");
            txtAPaterno.requestFocusInWindow();
            return;
        }
        if ("".equals(txtAMaterno.getText())) {
            JOptionPane.showMessageDialog(rootPane, "Ingrese el Apellido Materno");
            txtAMaterno.requestFocusInWindow();
            return;
        }
        if (cmbCarrera.getSelectedIndex() == 0) {
            JOptionPane.showMessageDialog(rootPane, "Seleccione una Carrera");
            return;
        }
        if (cmbSemestre.getSelectedIndex() == 0) {
            JOptionPane.showMessageDialog(rootPane, "Seleccione un Semestre");
            return;
        }
        //Inicia el insert
        try {
            ps = cn.prepareCall("{Call RAlumno(?,?,?,?,?,?)}");
            ps.setString(1, txtNumControl.getText());
            ps.setString(2, txtNombre.getText());
            ps.setString(3, txtAPaterno.getText());
            ps.setString(4, txtAMaterno.getText());
            ps.setInt(5, cmbCarrera.getSelectedIndex());
            ps.setInt(6, cmbSemestre.getSelectedIndex());

            int res = ps.executeUpdate();
            if (res == 1) {
                JOptionPane.showMessageDialog(rootPane, "Registro Exitoso");
            }
        } catch (SQLException | HeadlessException e) {
            JOptionPane.showMessageDialog(rootPane, "Error "+e.getMessage());
        }
        txtNumControl.setText("");
        txtNombre.setText("");
        txtAPaterno.setText("");
        txtAMaterno.setText("");
        cmbCarrera.setSelectedIndex(0);
        cmbSemestre.setSelectedIndex(0);
    }//GEN-LAST:event_btnGuargarActionPerformed

    private void btnLimpiar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiar1ActionPerformed
        //boton que limpia los campos de MAestros
        txtRFC.setText("");
        txtNombreM.setText("");
        txtAPeternoM.setText("");
        txtAMaternoM.setText("");
        cmbCarreraM.setSelectedIndex(0);
    }//GEN-LAST:event_btnLimpiar1ActionPerformed

    private void btnBuscarMaestroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarMaestroActionPerformed
        //boton de buscar maestro
         if("".equals(txtRFC.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingrese RFC");
            txtRFC.requestFocusInWindow();
            return;
        }
        //metodo buscar
        try {
            st=cn.prepareCall("{call BuscarM(?)}");
            st.setString(1, txtRFC.getText());
            r=st.executeQuery();
            if(r.next()){
                this.txtRFC.setText(r.getString(1));
                this.txtNombreM.setText(r.getString(2));
                this.txtAPeternoM.setText(r.getString(3));
                this.txtAMaternoM.setText(r.getString(4));
                this.cmbCarreraM.setSelectedIndex(r.getInt(5));
            }else{
                JOptionPane.showMessageDialog(rootPane, "Datos no encontrados");
            }
        } catch (SQLException | HeadlessException e) {
            JOptionPane.showMessageDialog(rootPane, "Error "+e.getMessage());
        }
    }//GEN-LAST:event_btnBuscarMaestroActionPerformed

    private void btnBuscarAlumnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarAlumnoActionPerformed
        //boton de buscar Alumno
        if("".equals(txtNumControl.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingrese numero de control");
            txtNumControl.requestFocusInWindow();
            return;
        }
        //metodo buscar
        try {
            st=cn.prepareCall("{call BuscarA(?)}");
            st.setString(1, txtNumControl.getText());
            r=st.executeQuery();
            if(r.next()){
                this.txtNumControl.setText(r.getString(1));
                this.txtNombre.setText(r.getString(2));
                this.txtAPaterno.setText(r.getString(3));
                this.txtAMaterno.setText(r.getString(4));
                this.cmbCarrera.setSelectedIndex(r.getInt(5));
                this.cmbSemestre.setSelectedIndex(r.getInt(6));
            }else{
                JOptionPane.showMessageDialog(rootPane, "Datos no encontrados");
            }
        } catch (SQLException | HeadlessException e) {
            JOptionPane.showMessageDialog(rootPane, "Error "+e.getMessage());
        }
    }//GEN-LAST:event_btnBuscarAlumnoActionPerformed

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
       // boton limpiar de Alumnos
        txtNumControl.setText("");
        txtNombre.setText("");
        txtNombre.setText("");
        txtAPaterno.setText("");
        txtAMaterno.setText("");
        cmbCarrera.setSelectedIndex(0);
        cmbSemestre.setSelectedIndex(0);
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void tbnActualizarAlumnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbnActualizarAlumnoActionPerformed
        // boton actualizar de Alumnos
        if ("".equals(txtNumControl.getText())) {
            JOptionPane.showMessageDialog(rootPane, "Ingrese Numero de Control");
            txtNumControl.requestFocusInWindow();
            return;
        }
        if ("".equals(txtNombre.getText())) {
            JOptionPane.showMessageDialog(rootPane, "Ingrese el Nombre");
            txtNombre.requestFocusInWindow();
            return;
        }
        if ("".equals(txtAPaterno.getText())) {
            JOptionPane.showMessageDialog(rootPane, "Ingrese el Apellido Paterno");
            txtAPaterno.requestFocusInWindow();
            return;
        }
        if ("".equals(txtAMaterno.getText())) {
            JOptionPane.showMessageDialog(rootPane, "Ingrese el Apellido Materno");
            txtAMaterno.requestFocusInWindow();
            return;
        }
        if (cmbCarrera.getSelectedIndex() == 0) {
            JOptionPane.showMessageDialog(rootPane, "Seleccione una Carrera");
            return;
        }
        if (cmbSemestre.getSelectedIndex() == 0) {
            JOptionPane.showMessageDialog(rootPane, "Seleccione un Semestre");
            return;
        }
        int i=JOptionPane.showConfirmDialog(rootPane, "Esta seguro de Actualizar al Alumno",
            "Confirmar", JOptionPane.YES_NO_CANCEL_OPTION);
        if(i==0){
        try {
            ps = cn.prepareCall("{call ActualizarA(?,?,?,?,?,?)}");
                ps.setString(1, this.txtNumControl.getText());
                ps.setString(2, this.txtNombre.getText());
                ps.setString(3, this.txtAPaterno.getText());
                ps.setString(4, this.txtAMaterno.getText());
                ps.setInt(5, this.cmbCarrera.getSelectedIndex());
                ps.setInt(6, this.cmbSemestre.getSelectedIndex());
                int res = ps.executeUpdate();
                if (res == 1) {
                    JOptionPane.showMessageDialog(rootPane, "Datos Actualizados");
                }
        } catch (SQLException | HeadlessException e) {
            JOptionPane.showMessageDialog(rootPane, "Error "+e.getMessage());
        }
        }else{
            JOptionPane.showMessageDialog(rootPane, "Actualizacion cancelada");
        }
        //limpia los campos
        txtNumControl.setText("");
        txtNombre.setText("");
        txtNombre.setText("");
        txtAPaterno.setText("");
        txtAMaterno.setText("");
        cmbCarrera.setSelectedIndex(0);
        cmbSemestre.setSelectedIndex(0);
    }//GEN-LAST:event_tbnActualizarAlumnoActionPerformed

    private void btnActualizarMaestroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarMaestroActionPerformed
        // boton Actualizar Maestro
        if("".equals(txtRFC.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingrese el RFC");
            txtRFC.requestFocusInWindow();
            return;
        }
        if("".equals(txtNombreM.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingresa un Nombre");
            txtNombreM.requestFocusInWindow();
            return;
        }
        if("".equals(txtAPeternoM.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingresa Apellido Paterno");
            txtAPeternoM.requestFocusInWindow();
            return;
        }
        if("".equals(txtAMaternoM.getText())){
            JOptionPane.showMessageDialog(rootPane, "Ingresa Apellido Materno");
            txtAMaternoM.requestFocusInWindow();
            return;
        }
        if(cmbCarreraM.getSelectedIndex()==0){
            JOptionPane.showMessageDialog(rootPane, "Selecciona una Carrera");
            return;
        }
        //metodo que actualiza
         int i=JOptionPane.showConfirmDialog(rootPane, "Esta seguro de Actualizar al Alumno",
            "Confirmar", JOptionPane.YES_NO_CANCEL_OPTION);
        if(i==0){
        try {
            ps = cn.prepareCall("{call ActualizarM(?,?,?,?,?)}");
                ps.setString(1, this.txtRFC.getText());
                ps.setString(2, this.txtNombreM.getText());
                ps.setString(3, this.txtAPeternoM.getText());
                ps.setString(4, this.txtAMaternoM.getText());
                ps.setInt(5, this.cmbCarreraM.getSelectedIndex());
                int res = ps.executeUpdate();
                if (res == 1) {
                    JOptionPane.showMessageDialog(rootPane, "Datos Actualizados");
                }
        } catch (SQLException | HeadlessException e) {
            JOptionPane.showMessageDialog(rootPane, "Error "+e.getMessage());
        }
        }else{
            JOptionPane.showMessageDialog(rootPane, "Actualizacion cancelada");
        }
    }//GEN-LAST:event_btnActualizarMaestroActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizarMaestro;
    private javax.swing.JButton btnBuscarAlumno;
    private javax.swing.JButton btnBuscarMaestro;
    private javax.swing.JButton btnGuargar;
    private javax.swing.JButton btnGuargar1;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnLimpiar1;
    private javax.swing.JComboBox cmbCarrera;
    private javax.swing.JComboBox cmbCarreraM;
    private javax.swing.JComboBox cmbSemestre;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton tbnActualizarAlumno;
    private javax.swing.JTextField txtAMaterno;
    private javax.swing.JTextField txtAMaternoM;
    private javax.swing.JTextField txtAPaterno;
    private javax.swing.JTextField txtAPeternoM;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNombreM;
    private javax.swing.JTextField txtNumControl;
    private javax.swing.JTextField txtRFC;
    // End of variables declaration//GEN-END:variables
}
